

package com.android.rotatey;

import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Paint; 
import android.graphics.RectF; 
import android.graphics.Paint.Style; 
import android.view.View;
import android.graphics.Color;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.Log;

public class RotateYView extends View{

    private static final String TAG = "RotateYView";
    private Context mContext;

    private Camera mCamera;
    private Matrix mMatrix;

    Bitmap mBitmap;
    Canvas mCanvas;
    Paint mPaint = new Paint();


    public RotateYView(Context context) {
        super(context);
    
        mContext = context;

        mBitmap = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas (mBitmap);

        mPaint = new Paint ();
        mPaint.setARGB(150, 255, 255, 255);
        mPaint.setTextSize(65);

        mCamera = new Camera();

    }


    @Override
    protected void onDraw(Canvas canvas) {

        super.onDraw(canvas);

        if (mBitmap != null) {
           
            int angle = 80;

            for (int i = 0; i < 10; i++) {
            //BLACK
            mBitmap.eraseColor (0xff000000);
            mCanvas.setBitmap(mBitmap);

            Matrix m = mCanvas.getMatrix ();
            mCamera.save ();
            mCamera.rotateY (angle);
            mCamera.getMatrix (m);
            mCamera.restore ();
            mCanvas.setMatrix (m);  
 
            mCanvas.drawText ("5", 0, 50, mPaint);
            canvas.drawBitmap(mBitmap, 10 + i * 30 + 10, (this.getHeight() / 2) + 30, mPaint);

            angle = angle - 20;
        }

        }
            
    }

    
}
